package web.page;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ContactPage {

    WebDriver driver;

    public ContactPage(WebDriver driver) {
        this.driver=driver;
    }

    public ContactPage add(){

        return this;
    }

    public void delete(){

    }

    public ContactPage searchDept(String deptName){
        driver.findElement(By.id("memberSearchInput")).sendKeys(deptName);
        return this;
    }

    public ContactPage searchTag(String tag){
        driver.findElement(By.cssSelector(".qui_inputText.ww_inputText.ww_searchInput_text.js_search_in")).sendKeys(tag);
        return this;
    }

    public String searchMbrResult(){
        return driver.findElement(By.cssSelector(".ww_searchResult_title_peopleName")).getText();
    }

    public String searchDeptResult(){
        return driver.findElement(By.cssSelector(".ww_searchResult_item_Curr")).getAttribute("title");
    }

    public String searchTagResult(){
        return driver.findElement(By.cssSelector(".ww_searchResult_item_Curr a")).getText();
    }

    public void importMember(String filePath) throws InterruptedException {
        Thread.sleep(3000);
        driver.findElement(By.cssSelector(".js_has_member .ww_btn_PartDropdown_left")).click();
        driver.findElement(By.linkText("文件导入")).click();
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("[type=file]")).sendKeys(filePath);
        driver.findElement(By.id("submit_csv")).click();
        driver.findElement(By.linkText("前往查看")).click();
    }

    public void exportMember(){

    }

    public void addDepartment(String deptName){
        driver.findElement(By.cssSelector(".member_colLeft_top_addBtn")).click();
        driver.findElement(By.linkText("添加部门")).click();
        driver.findElement(By.name("name")).sendKeys(deptName);
        driver.findElement(By.linkText("选择所属部门")).click();
        driver.findElement(By.cssSelector(".member_tag_dialog_inputDlg .qui_dropdownMenu ul li a")).click();//选中第一个部门
        driver.findElement(By.cssSelector("[d_ck=\"submit\"]")).click();
    }

    public void addMember(String username,String id,String num){
        driver.findElement(By.linkText("添加成员")).click();
        driver.findElement(By.id("username")).sendKeys(username);
        driver.findElement(By.id("memberAdd_acctid")).sendKeys(id);
        driver.findElement(By.id("memberAdd_phone")).sendKeys(num);
        driver.findElement(By.cssSelector(".qui_btn.ww_btn.js_btn_save")).click();
    }

    public void addTag(String tagName,String deptName) throws InterruptedException {
        driver.findElement(By.linkText("标签")).click();
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("[on-click=\"createTag\"]")).click();
        driver.findElement(By.name("name")).sendKeys(tagName);
        driver.findElement(By.cssSelector(".ww_btnWithMenu.js_btnWithMenu.js_share_dialog_range_wrap")).click();
        driver.findElement(By.linkText(deptName)).click();
        driver.findElement(By.cssSelector("[d_ck=\"submit\"]")).click();
    }

    public String getMember(){

        return "123";
    }
}
